<template>
	<!-- 修改昵称 -->
	<view class="nickname">
		<!-- #ifdef APP-PLUS -->
		<top-set></top-set>
		<tab-top fixed="true" title="修改昵称"></tab-top>
		<!-- #endif -->
		<view class="bg_01"></view>
		<view class="set_box">
			<view class="set_item">
				<view class="set_item_left">
					<input class="input" type="text" v-model="username" maxlength="10" minlength='2' placeholder="请输入昵称"/>
				</view>
			</view>
			<!-- <text class="subscript">2-10个字符，支持中英文、数字</text> -->
		</view>	
		<button class="button" @tap="nickname">确定</button>
	</view>
</template>

<script>
	let flag = false;//重复点击开关 
	export default{
		data() {
			return {
				username:''
			}
		},
		onLoad() {
			this.username = this.$store.state.username
		},
		methods: {
			nickname() {
				if(this.username.length < 2 || this.username.length > 10 ){
					this.showToast('请正确填写昵称');
					return;
				}
				/**
				 * 提交用户昵称
				 */
				if(flag){
					return;
				}
				flag = true;
				console.log(this.username)
				this.req({
						url: 'user/editAccountInfo',
						// id:this.isLogin().id,
						data: {
							id:this.isLogin().id,
							username: this.username
						}
					},
					(res) => {
						this.modifyUserInfo('username',this.username);
						this.updateUserInfo()
						uni.navigateBack({
							delta: 1
						});
						flag = false;
					},
					(err) => {
						uni.showToast({
							title: '上传失败，请重试'
						});
						flag = false;
					}
				);
			}
		},
	}
</script>

<style lang="scss" scoped>
.nickname{
	font-family: PingFang-SC-Medium;
	font-weight: normal;
	font-stretch: normal;
	letter-spacing: 0px;
	color: #333333;
	.set_box{
		width: 702upx;
		height: 296upx;
		padding: 0 24upx;
		.set_item{
			height: 98upx;
			border-bottom: 1upx solid #e5e5e5;
			.set_item_left{
				.input[type]{
					font-size: 30upx;
					line-height: 98upx;
					height: 98upx;
				}
			}
		}
		.subscript{
			font-size: 24upx;
			color: #999999;
		}
	}
	.button{
		width: 540upx;
		height: 90upx;
		border-radius: 8upx;
		font-size: 32upx;
		line-height: 90upx;
		background-color: #3595f9;
		color: #fefefe;
	}
	.bg_01{
		width: 750upx;
		height: 30upx;
		background-color: #f0f0f0;
	}
}
</style>

